// pages/home/company/company.js
const app = getApp()
const globalIp = app.globalData.userIp
Page({

  /**
   * 页面的初始数据
   */
  data: {
    inputShowed: false,
    inputVal: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      search: this.search.bind(this),
    })   
  },

  search: function (value) {
    var cardInfo = [];
    var result = new Object();
    result.text = '';
    result.value = '';
    var resultList=[];
    wx.request({
      url: globalIp + 'home/ocrd/getCardInfo',
      data: {
        value: value
      },
      header: {
        'content-type': 'application/json'
      },
      method: 'POST',
      success: function(res) {
        cardInfo = res.data.cardInfo.data
        console.log(res.data.cardInfo.data)
      },
      fail: function(res) {
        console.log("请求失败")
      }
    })
    return new Promise((resolve, reject) => {
      setTimeout(() => {
          // resolve([{text: '搜索结果', value: 1}, {text: '搜索结果2', value: 2}])
          for (var i of cardInfo) {
            result.text = i.CardName;
            result.value = i.CardCode;
            resultList.push(result);
            result = {};
          }
          resolve(resultList);
      }, 200)
    })      
  },
  selectResult: function (e) {
      console.log('select result', e.detail)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },
  
})